package com.angelhack.metrosocial.adapters;

import java.util.ArrayList;

import com.angelhack.metrosocial.R;
import com.angelhack.metrosocial.ui.ShowImage;
import com.angelhack.metrosocial.utils.ComentariosEstacion;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class ComentariosAdapter extends ArrayAdapter<ComentariosEstacion>{

private ArrayList<ComentariosEstacion> items;
private Context context;
	public ComentariosAdapter(Context context, int textViewResourceId,
			ArrayList<ComentariosEstacion> objects) {
		super(context, textViewResourceId, objects);
		items = objects;
		this.context = context;
	}
	@Override
	public int getCount() {
		return items.size();
	}
	@Override
	public ComentariosEstacion getItem(int position) {
		return items.get(position);
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		//todo holder
		LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View v = li.inflate(R.layout.list_comentario_single, null);
		TextView txtUser = (TextView)v.findViewById(R.id.txtUser);
		TextView txtComentario = (TextView)v.findViewById(R.id.txtComentario);
		ImageView imgUser = (ImageView) v.findViewById(R.id.imgComentario);
		
		final ComentariosEstacion est = getItem(position);
		txtUser.setText(est.getUser());
		txtComentario.setText(est.getComentarios());
		int color= context.getResources().getColor(R.color.green);
		switch (est.getEstadoServicio()) {
		case 1:
			color = context.getResources().getColor(R.color.yellow);
			break;
		case 2:
			color = context.getResources().getColor(R.color.red);
			break;
		}
		txtUser.setTextColor(color);
		if(est.getImg().equals("0"))
		{
			imgUser.setVisibility(View.GONE);
		}else
		{
			imgUser.setVisibility(View.VISIBLE);
			imgUser.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Intent i = new Intent(context ,ShowImage.class);
					i.putExtra("id", est.getId());
					i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					context.startActivity(i);
					Toast.makeText(context, "Tiene IMG", Toast.LENGTH_SHORT).show();
				}
			});
		}
		
		return v;
	}


}
